home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
dev
/
misc
/
egs.lha
/
EGS
/
EGS_Devels
/
Examples
/
EGS_Gadget
/
gadget.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-17
|
9KB
|
315 lines
/*
** CHANGE : 14. Jul 1992 mvk
** 17. Dez 1992 mvk
** 09 Jan 1993 mvk
**
** This is an example of how to use context-sensitive gadgets.
**
** It is like TeX: you create boxes and into the boxes
**
** you put gadgets. The system will fit these gadgets
**
** into the window for you. In this program you see
**
** no absolute position of any gadget.
**
**
** (C) by VIONA Development 1991,1993
**
*/
#include "includes.c"
EI_WindowPtr CreateGads (void);
struct Library *EGSIntuiBase;
struct Library *EGBBase;
struct Library *EGBScrollBase;
struct Library *EGBRadioBase;
struct Library *EGBSetBase;
struct Library *EGBSelectBase;
struct Library *EGBTextInfoBase;
EI_WindowPtr window;
EI_EIntuiMsgPtr msg;
EB_GadContext con;
EB_StrArray Texts = { "This is a demonstration",
"of the gadbox.library !",
"It supports all different ",
"types of gadgets which are ",
"scalable by sizing the window.", NULL };
EB_StrArray Gads1 = { " 8","13","18","24","40",NULL };
EB_StrArray Gads2 = { "OK","CANCEL",NULL };
EB_StrArray2 Gadgs = { &Gads1, &Gads2, NULL };
char infotext[] = "Information gadget:\n\n"
"This is a text information gadget, it may provide"
"the user with helpful information about the program.\n"
"The gadget has an automatic wordwrap to allow different"
"font and box sizes, and is completely self handled.\n\n"
"This requester contains several different gadget types, "
"which are all created using the egsgadbox.library.\n";
EI_WindowPtr CreateGads (void)
{
EB_GadBoxPtr root, help;
EI_GadgetPtr tgad;
con = EB_CreateGadContext(NULL,NULL,-1,-1);
root = EB_CreateHorizBox(con);
/*
** Create vertical propgadget on the left side
*/
EB_AddLastSon(root, EB_CreateSuperVertiProp(con, 20, 4, 5, 0x2000,
EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT ));
EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
help = EB_CreateVertiBox(con);
/*
** Create a textbox on the top of the left side
*/
EB_AddLastSon(help, EB_CreateBackBorder(con,
EB_CreateMultiText(con, &Texts),0));
EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
/*
** Make some boolgadgets
*/
EB_AddLastSon(help, EB_CreateMultiAction2(con, &Gadgs,0x1000 ));
EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
EB_AddLastSon(help, EB_CreateSuperHorizProp(con, 20, 4, 5, 0x2001,
EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT ));
EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
/*
** Make two stringgadgrets
*/
EB_AddLastSon(help, EB_CreateNameStringGadget(con, "name", 20, 100,
EI_JUSTIFY_LEFT, 0x3000));
EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
EB_AddLastSon(help, EB_CreateNameStringGadget(con, "path", 20, 100,
EI_JUSTIFY_LEFT, 0x3000));
EB_AddLastSon(help, EB_CreateVertiFill(con,0,0));
/*
** Create a scroll textbox
*/
EB_AddLastSon(help, EGB_CreateTextInfoGadget(con, 10, 40, 5, 10,
NULL, 0x6000));
EB_AddLastSon(root, help);
EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
EB_AddLastSon(root, EB_CreateSuperVertiProp(con, 20, 4, 5, 0x2002,
EB_DEC_UP_LEFT|EB_INC_BOTTOM_RIGHT ));
EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
/*
** Create a scrollbox with items (The items are appended in the main() function)
**
** If the sort flag is set (TRUE),
** the items will be inserted in alphabetical order.
*/
EB_AddLastSon(root, EGB_CreateLateScrollBox(con,20,40,10,20,TRUE,0x3000));
EB_AddLastSon(root, EB_CreateHorizFill(con,0,0));
help = EB_CreateHorizBox(con);
/*
** Create some radio boolgadgets (vertcial)
*/
EB_AddLastSon(help, EGB_CreateRadioGadget(con,&Gads1,100,0x4000));
EB_AddLastSon(help, EB_CreateHorizFill(con,0,0));
/*
** Create some boolgadgets (vertical)
*/
EB_AddLastSon(help, EGB_CreateSetGadget(con,&Gads1,100,0x4001));
EB_AddLastSon(root,help);
if (EB_ProcessGadBoxes(con, root))
{
tgad = EB_FindGadget(con->First, con->Num, 0x6000);
if (tgad)
{
EGB_ModifyTextInfoGadget(NULL, tgad, infotext);
}
con->NewWin->IDCMPFlags = EI_iCLOSEWINDOW;
con->NewWin->Bordef.SysGadgets |= (EI_WINDOWCLOSE);
con->NewWin->MaxWidth = 800;
con->NewWin->MaxHeight = 600;
return (EI_OpenWindow(con->NewWin));
}
else
return NULL;
}
void Crash (char * string)
{
if (NULL != window)
EI_CloseWindow( window );
if (NULL != con)
EB_DeleteGadContext(con);
if (NULL != EGSIntuiBase)
CloseLibrary( EGSIntuiBase );
if (NULL != EGBBase)
CloseLibrary( EGBBase );
if (NULL != EGBScrollBase)
CloseLibrary( EGBScrollBase );
if (NULL != EGBRadioBase)
CloseLibrary( EGBRadioBase );
if (NULL != EGBSelectBase)
CloseLibrary( EGBSelectBase );
if (NULL != EGBTextInfoBase)
CloseLibrary( EGBTextInfoBase );
if (NULL == string)
exit (0);
else
{
printf ("%s.\n", string);
exit (10);
}
}
void main (void)
{
struct Node item1,item2,item3,item4;
EI_GadgetPtr gad;
window = NULL;
con = NULL;
EGSIntuiBase = OpenLibrary ( "egsintui.library", 0 );
if (NULL == EGSIntuiBase)
Crash ( "Could not open egsintui.library" );
EGBBase = OpenLibrary ( "egsgadbox.library", 0 );
if (NULL == EGBBase)
Crash ( "Could not open egsgadbox.library" );
EGBScrollBase = OpenLibrary ( "egb/gbscrollbox.library", 0 );
if (NULL == EGBScrollBase)
Crash ( "Could not open egb/gbscrollbox.library" );
EGBRadioBase = OpenLibrary ( "egb/gbradio.library", 0 );
if (NULL == EGBRadioBase)
Crash ( "Could not open egb/gbradio.library" );
EGBSetBase = OpenLibrary ( "egb/gbsets.library", 0 );
if (NULL == EGBSetBase)
Crash ( "Could not open egb/gbsets.library" );
EGBSelectBase = OpenLibrary ( "egb/gbselect.library", 0 );
if (NULL == EGBSelectBase)
Crash ( "Could not open egb/gbselect.library" );
EGBTextInfoBase = OpenLibrary ( "egb/gbtextinfo.library", 0 );
if (NULL == EGBTextInfoBase)
Crash ( "Could not open egb/gbtextinfo.library" );
window = CreateGads();
gad = EB_FindGadget(con->First, con->Num, 0x3000);
if(gad)
{
/*
** if Pri = 1 then the item is on top of the list
** and highlighted (use of directories a.s.o)
*/
item1.ln_Pri=0;
item2.ln_Pri=0;
item3.ln_Pri=0;
item4.ln_Pri=0;
item1.ln_Name="d_Text1";
item2.ln_Name="b_Text2";
item3.ln_Name="a_Text3";
item4.ln_Name="c_Text4";
EGB_AddItemToScrollBox(window, gad, &item1);
EGB_AddItemToScrollBox(window, gad, &item2);
EGB_AddItemToScrollBox(window, gad, &item3);
EGB_AddItemToScrollBox(window, gad, &item4);
}
if (NULL == window)
Crash ("Could not open window");
for (;;)
{
while (NULL == (msg = (EI_EIntuiMsgPtr) GetMsg ( window->UserPort )))
WaitPort ( window->UserPort );
switch (msg->Class)
{
case EI_iCLOSEWINDOW:
ReplyMsg ( (struct Message*)msg );
Crash (NULL);
break;
default:
printf (" Unknown message %ld\n", msg->Class);
ReplyMsg ( (struct Message*)msg );
}
} /* forever */
}